package com.zw.goods.controller;


import com.zw.commons.log.annotation.Log;
import com.zw.commons.log.enums.BusinessType;
import com.zw.goods.service.GoodInfoService;
import com.zw.object.goods.GoodInfo;
import com.zw.object.result.Result;
import com.zw.object.vo.GoodInfoTotalVo;
import com.zw.object.vo.GoodInfoVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.security.Principal;

/**
 * <p>
 * 物资信息表 前端控制器
 * </p>
 *
 * @author zw
 * @since 2023-03-15
 */
@Api(tags = "物资信息")
@RestController
@RequestMapping("/goods/good-info")
public class GoodInfoController {
    @Autowired
    private GoodInfoService goodInfoService;

    @GetMapping("/all")
    @ApiOperation("全部物资信息")
    @Log(title = "全部物资信息",businessType = BusinessType.SELECT)
    public Result all(){
        return goodInfoService.goodInfoAll();
    }

    @PostMapping("/total")
    @ApiOperation("获取物资总数")
    @Log(title = "获取物资总数",businessType = BusinessType.SELECT)
    public Result total(@Validated @RequestBody GoodInfoTotalVo vo){
        return goodInfoService.goodInfoTotal(vo);
    }

    @PostMapping("/list")
    @ApiOperation("获取物资信息带分页")
    @Log(title = "获取物资信息，带分页",businessType = BusinessType.SELECT)
    public Result list(@Validated @RequestBody GoodInfoVo vo){
        return goodInfoService.list(vo);
    }

    @PostMapping("/save")
    @ApiOperation("新增物资")
    @Log(title = "薪资物资",businessType = BusinessType.INSERT)
    public Result save(@RequestParam("img") MultipartFile file, @RequestParam("goodInfo") String json, HttpServletRequest request) throws IOException {
        return goodInfoService.save(file,json,request);
    }

    @PostMapping("/update")
    @Log(title = "更新物资信息",businessType = BusinessType.ASSGIN)
    @ApiOperation("更新物资信息")
    public Result update(@RequestParam(value = "img", required = false) MultipartFile file, @RequestParam("goodInfo") String json) throws IOException {
        return goodInfoService.update(file,json);
    }

    @PostMapping("/delete")
    @ApiOperation("删除物资信息")
    @Log(title = "删除物资信息",businessType = BusinessType.DELETE)
    public Result delete(@RequestBody @RequestParam("ids") Long[] ids){
        return  goodInfoService.delete(ids);
    }
}

